﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using NLBS.Entity;
using NLBS.Data;
using NLBS.Framework;
using NLBS.Resources;
using NLBS.Web;
using NLBS.Web.UI;

namespace NLBS.Control
{
    public class BaseUserControl :UserControl
    {
        protected void checkAdmin()
        {
            if (!Request.IsAuthenticated && BlogInfo.Instance().CurrentUser.Group.GroupID != 1)
            {
                throw new Exception("没有操作的权限");
            }
        }



        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
        }

        public string GetSettingValue(string setName,bool isvalue1)
        {
            Setting set = GetSetting(setName);
            string setValue;
            if (isvalue1)
            {
                setValue = set.Value1.ToString();
                
            }
            else
            {
                setValue = set.Value0.ToString();
            }
            return setValue;
        }
        public string GetSettingValue(string setName)
        {
             Setting set = GetSetting(setName);
             if (set.Value1 == null || set.Value1 == string.Empty)
             {
                 return set.Value0.ToString();
             }
            return GetSettingValue(setName,true);
        }
        public string GetSettings(string setName)
        {
           return GetSettingValue(setName);
        }
        public BlogInfo BlogInfo
        {
            get
            {
                return BlogInfo.Instance();
            }
        }

        public Right Power
        {
            get
            {
                return BlogInfo.CurrentUser.Group.Power;
            }
        }

        public Setting GetSetting(string setName)
        {
            return BlogInfo.Instance().GetSetting(setName);
        }

        public Dictionary<string, string> lang
        {
            get
            {
                return Language.Instance().getLanguage();
            }
        }
       

        public UrlFormatsProvider urlFormats
        {
            get
            {
                return UrlFormatsProvider.Instance();
            }
        }

        public ReWriteUrls reUrlFormats
        {
            get
            {
                return ReWriteUrls.Instance();
            }
        }


        public string BaseUrl
        {
            get
            {
                return BlogInfo.Instance().BaseUrl;
            }
        }

        public string UserName
        {
            get
            {

                return HttpContext.Current.User.Identity.Name;
            }
        }

        public void ShowError(string error)
        {
            this.Controls.Clear();
            this.Controls.Add(new MessageBox(NLBS.Web.UI.MessageType.Error, "错误", error, "返回"));
        }
    }
}
